home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / croutes.zip / UNLUMP.C < prev    next >
Text File  |  1983-12-30  |  1KB  |  70 lines

  1. /* UNLUMP:  Break apart files lumped together by LUMP */
  2.  
  3. #include "stdio.h"
  4.  
  5. #define  BUFL  512
  6.  
  7. FILE *infile, *outfile;
  8.  
  9. main(argc,argv)
  10. int argc;
  11. char *argv[];
  12. {
  13.    int c, i;
  14.    char filename[61];
  15.    char buf[BUFL];
  16.    int opened = 0;
  17.  
  18.    if(argc<2)  { usage(); exit(0); }
  19.  
  20.    argc--;
  21.    if( (infile=fopen(argv[1], "r")) == NULL )     inerr();
  22.    while( fgets(buf, BUFL, infile) != NULL )  {
  23.       filename[0] = '\0';
  24.       sscanf( buf, "*FILE: %60s", filename );
  25.       if( filename[0] != '\0' )  {
  26.          if(opened)  fclose(outfile);
  27.          printf( "*FILE: %s\n", filename );
  28.          if( (outfile=fopen(filename,"w")) == NULL )    outerr();
  29.          opened = 1;
  30.          continue;
  31.          }
  32.       if( !opened )  fmterr();
  33.       if( fputs(buf, outfile) == EOF )  outerr();
  34.       }
  35.    if( ferror(infile) )  inerr();
  36.    fclose(infile);
  37. }
  38.  
  39.  
  40. usage()
  41. {
  42.    printf("Usage:  unlump infile \n");
  43.    printf("   UnLump the input file into output files named in it.\n");
  44.    printf("   Files are separated by  a line with the format:\n");
  45.    printf("      *FILE: filename.ext\n\n");
  46. }
  47.  
  48.  
  49. inerr()
  50. {
  51.    printf("\nError opening or reading input file \n");
  52.    fclose(infile);
  53.    exit(1);
  54. }
  55.  
  56.  
  57. outerr()
  58. {
  59.    printf("\nError opening or writing output file \n");
  60.    fclose(outfile);
  61.    exit(1);
  62. }
  63.  
  64.  
  65. fmterr()
  66. {
  67.    printf("\nFile does not have proper LUMP format\n");
  68.    exit(1);
  69. }
  70.